#include <stdio.h>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <sstream>
#include <iostream>
#include <string>
#include "Game.h"
#include "Map.h"
#include "Unit.h"

#define TITLE "SQUADRONLOLOL"
#define WIDTH 800
#define HEIGHT 600
#define FPS 60

int main(int argc, char *argv[]) {
    // initialize window
    sf::RenderWindow app(sf::VideoMode(WIDTH, HEIGHT, 32), TITLE);
    app.UseVerticalSync(true);
    //app.SetFramerateLimit(FPS);

    // start a new game
    Game game(app);
    game.Init();

    // main loop
    while (app.IsOpened()) {
        // process events
        sf::Event event;
        while (app.GetEvent(event)) {
            if (event.Type == sf::Event::Closed) {
                app.Close();
            }
            else {
                game.HandleEvent(event);
            }
        }

        float deltaTime = app.GetFrameTime();
     
        // update and render
        app.Clear();
        game.Update(deltaTime);
        game.Render(app);

        std::stringstream stream; 
        stream << (int)(1/deltaTime);
        std::string fps;
        stream >> fps;
        String string(fps);
        app.Draw(string);
        // display 
        app.Display();
    }

    // end game
    game.End();

    return 0;
}

